package com.googlecode.afx.view.fxml;

import com.googlecode.afx.view.View;

import javafx.scene.layout.BorderPane;

public class FxmlPanelView extends AbstractFxmlDatabindingView {

	@Override
	public void showAfterBind() {
		
		View parent = (View) this.getViewCache().lookupComponent(this.getParentId());
		if (parent != null) {
			if (parent.getNode() instanceof BorderPane) {
				this.handleParentViewBorderPane((BorderPane) parent.getNode());
			}
		}
		
		if(this.hasErrorOccured()) {
			this.displayThrowable();
			this.resetError();
		}
	}

	private void handleParentViewBorderPane(BorderPane parentBorderPane) {
		switch (this.getPosition()) {
		case TOP:
			parentBorderPane.setTop(this.getNode());
			break;
		case BOTTOM:
			parentBorderPane.setBottom(this.getNode());
			break;
		case LEFT:
			parentBorderPane.setLeft(this.getNode());
			break;
		case RIGHT:
			parentBorderPane.setRight(this.getNode());
			break;
		case CENTER:
			parentBorderPane.setCenter(this.getNode());
			break;
		}
	}


}
